package com.zh.config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

public class MybatisConfiguration {
//    <bean class="org.mybatis.spring.SqlSessionFactoryBean">-->
//        <property name="dataSource" ref="dataSource"/>-->
//        <property name="typeAliasesPackage" value="com.zh.bean"/>-->
//    </bean>
    @Value("com.zh.bean")
    private String typeAliasesPackage;
//        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
//        <property name="BasePackage" value="dao"/>
//    </bean>
//    @Value("${com.zh.dao}")
//    private String basePackage;

    @Bean
    public SqlSessionFactoryBean getSqlSessionFactoryBean(@Autowired DataSource dataSource) {
        SqlSessionFactoryBean ssf = new SqlSessionFactoryBean();
        ssf.setDataSource(dataSource);
        ssf.setTypeAliasesPackage("com.zh.dao");
        return ssf;
    }

    @Bean
    public MapperScannerConfigurer getMapperScannerConfigurer() {
        MapperScannerConfigurer msc = new MapperScannerConfigurer();
        msc.setBasePackage("com.zh.dao");
        return msc;
    }
}
